package main

import (
	"fmt"
	"math"
)

type ErrorInfo struct {
	Num     float64
	problem string
}

func crash() {
	panic("crash")
}

func test() {
	defer func() {
		if e := recover(); e != nil {
			fmt.Printf("ing :%s\n", e)
		}
	}()
	crash()
	fmt.Printf("after bad call\n")
}

func (e ErrorInfo) Error() string {
	return fmt.Sprintf("错误， %f 小于0", e.Num)
}

func Sqrt(f float64) (float64, error) {

	fmt.Printf("Calling test\n")
	test()
	fmt.Printf("Test completed\n")

	if f < 0 {
		return -1, ErrorInfo{Num: f}
	}
	return math.Sqrt(f), nil
}

func main() {

	result, err := Sqrt(5)
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(result)
	}

}
